<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<x:parse xml="${param.xmlstr}" var="xmlData" />
<c:set var="grantCode"><x:out select="$xmlData/data/proposal/grant_code" /></c:set>
<c:choose>
<c:when test="${grantCode == 508}"><c:set var="title">其他主要参加单位</c:set></c:when>
<c:otherwise><c:set var="title">合作单位信息</c:set></c:otherwise>
</c:choose>

<div class="t_bar">${title }</div>
					<table  id="tblAttendOrg" cellpadding="0" class="table01 t_css" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
					<thead >
					<tr style="border:1px solid #B7D1E6">
						<th class="TblHead" align="center"  width="7%">选择</th>
						<th class="TblHead" align="center"  width="7%">序号</th>
						<th class="TblHead" align="center"  width="30%">单位名称</th> 
						<th class="TblHead" align="center"  width="30%">单位地址</th>  
				        <th class="TblHead" align="center"  width="13%">联系人</th> 
						<th class="TblHead" align="center"  width="13%">联系电话</th>         
					</tr>
			</thead>
			<tbody id="tab">
					<tr style="display:none"  align="center">
						<td align="center">&nbsp;
							<input type="radio" class="radiobutton" name="selAttendOrg" >
						</td>
						<td align="center">&nbsp;
							<span name="attendorgs|attendorg[0]@seq_no" >[index]</span> 
						</td>
						<td align="center">
						<input name="attendorgs|attendorg[0]|cname" class="required input_text" label="单位名称" value="" maxlength="50" style="width:80%">
						</td>
						<td align="center">
						<input name="attendorgs|attendorg[0]|address" class="required input_text" label="单位地址" value="" maxlength="50" style="width:80%">
						</td>
						<td align="center"><input name="attendorgs|attendorg[0]|contact_psn_name" class="required input_text" label="联系人" value="" maxlength="25" style="width:80%">
						</td>
						<td align="center"><input name="attendorgs|attendorg[0]|contact_psn_tel" class="required input_text" label="联系电话" value="" maxlength="25" style="width:80%">
						</td>
				</tr>
				<c:set value="0" var="index" scope="page"/>
					<x:forEach select="$xmlData/data/attendorgs/attendorg" var="attendorg">
					
					<c:choose>
						<c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
						<c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
					</c:choose>
					<tr  align="center">
						<td>&nbsp;
							<input type="radio" class="radiobutton" name="selAttendOrg" >
						</td>
						<td align="center">
							<span   name="attendorgs/attendorg[${flag}${index}]@seq_no" ><x:out select="$attendorg/@seq_no"/></span> 
						</td>
						<td >
						<input name="attendorgs/attendorg[${flag}${index}]/cname" class="required input_text" label="单位名称" value="<x:out select="$attendorg/cname"/>" maxlength="50" style="width:80%">
						</td>
						<td >
						<input name="attendorgs/attendorg[${flag}${index}]/address" class="required input_text" label="单位地址" value="<x:out select="$attendorg/address"/>" maxlength="50" style="width:80%">
						</td>
						<td ><input name="attendorgs/attendorg[${flag}${index}]/contact_psn_name" class="required input_text" label="联系人" value="<x:out select="$attendorg/contact_psn_name"/>" maxlength="25" style="width:80%">
						</td>
						<td ><input name="attendorgs/attendorg[${flag}${index}]/contact_psn_tel" class="required input_text" label="联系电话" value="<x:out select="$attendorg/contact_psn_tel"/>" maxlength="25" style="width:80%">
						</td>
						</tr>
					<c:set value="${index+1}" var="index" scope="page"/>
					</x:forEach>
				</tbody>
					</table>
					<table width="98%" align="center" border="0">
					<tr style="border: 0"><td style="border: 0">
					<input name="proposal/yanzheng_org" type="hidden" id="yanzheng_org" value="<x:out select="$xmlData/data/proposal/yanzheng_org" />">
					<input class="button" name="cmdAddbefore" type=button value="添加" onclick="org_numjia();addNewRow('tblAttendOrg');try{top.resizeFrame();}catch(e){};">
					<input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev('tblAttendOrg','selAttendOrg')">
					<input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext('tblAttendOrg','selAttendOrg')">
					<input class="button" name="cmddel" type=button  value="删除" onclick="if(deleteSelectedRow('tblAttendOrg','${title }'))org_numjian();">
					</td></tr>
	</table>
					
<script type="text/javascript">
function org_numjia(){
	var orgNum = $("#yanzheng_org").val();
	if(orgNum!=""&&orgNum!=null) {
		orgNum = parseInt(orgNum);
	}else{
		orgNum = 0;
	}
	
	orgNum = orgNum+1;
	$("#berif90905").text("是");
	$("#berif91011").text("是");
	$("#yanzheng_org").val(orgNum);
	
	
}
function org_numjian(){
	var orgNum = $("#yanzheng_org").val();
	if(orgNum!=""&&orgNum!=null) {
		orgNum = parseInt(orgNum);
		if(orgNum!=0) orgNum = orgNum-1;
		
	}else{
		orgNum = 0;
		
	}
	if(orgNum==0){
		$("#berif90905").text("否");
		$("#berif91011").text("否");
	}else{
		$("#berif90905").text("是");
		$("#berif91011").text("是");
	}
	$("#yanzheng_org").val(orgNum);
	
	
}

$(function(){
	$("#orgInfo tr:even").addClass("li_1");
    $("#orgInfo tr:odd").addClass("li_2");
    $("#orgInfo2 tr:even").addClass("li_1");
    $("#orgInfo2 tr:odd").addClass("li_2");
    $("#orgInfo3 tr:even").addClass("li_1");
    $("#orgInfo3 tr:odd").addClass("li_2");
    $("#fmzl tr:even").addClass("li_1");
    $("#fmzl tr:odd").addClass("li_2");
    $("#tblAttendOrg tr:even").addClass("li_1");
    $("#tblAttendOrg tr:odd").addClass("li_2");
    
    var table =document.getElementById("tblAttendOrg");
    var rows = table.rows.length;
    var orgNum = rows-2; //去掉表头
    if(orgNum==0){
		$("#berif90905").text("否");
		$("#berif91011").text("否");
	 }else{
		$("#berif90905").text("是");
		$("#berif91011").text("是");
	 }
    $("#yanzheng_org").val(orgNum);
    
});
/**
 * 增加一行
 * @param tableId表格Id
 * @param radioId
 * @param nNewRowPosition
 * @param startRowIndex
 */ 
/* function addNewRowDeal(table)
{
	if(table.attr("id")=='tblAttendOrg'){
		var maxLinNum=table.find("tr[name='externTr']").length-2;;//获得行数，减去表头和隐藏行
		var lineNum=""+(maxLinNum+1);
		
		var addHtml=table.find("tr[name='externTr']")[1].innerHTML;//获得隐藏行的html,查找第二行
		addHtml=addHtml.replace(/\[index\]/g,lineNum);
		lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
		if (lineNum.length==1)//如果是个位数，前面补0
			lineNum="0"+lineNum;
		addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
		addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
		
		table.append("<tr name='externTr'>"+addHtml+"</tr>");//将html增加到最后
	}else{
		var maxLinNum=table.find("tr").length-2;;//获得行数，减去表头和隐藏行
		var lineNum=""+(maxLinNum+1);
		
		var addHtml=table.find("tr")[1].innerHTML;//获得隐藏行的html,查找第二行
		addHtml=addHtml.replace(/\[index\]/g,lineNum);
		lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
		if (lineNum.length==1)//如果是个位数，前面补0
			lineNum="0"+lineNum;
		addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
		addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
		
		table.append("<tr >"+addHtml+"</tr>");//将html增加到最后
	}
} */
/**
 * 重新计算行号
 * @param tblId
 */
/* function refreshRowINdex(tblId){
	 //重新计算行号

	if(tblId=='tblAttendOrg'){
	  $("#"+tblId+" tr[name='externTr']").each(function(){
		  
		   var seq=$(this).get(0).rowIndex;//获得行数
		   if(seq>1){//如果有行  显示时display行不计入类，故只减1
			   
			   seq=seq-1;
			   var seq_no=$(this).find("[name$='seq_no']");
			   if(seq_no.is("span"))
				   seq_no.html(seq);
			   else
				   seq_no.val(seq);
			   
			   seq=""+(seq-1);
			   if(seq.length==1)
				   seq="0"+seq;
			  //替换相应的name参数的seq
			  $(this).find("input,span,textarea,select").each(function(){
				   var name=$(this).attr("name");
				   if(name!=null&&name!=""){
					   name=name.replace(/\[\d*\]/g,"["+seq+"]");
					   $(this).attr("name",name);
				   }
				   var id=$(this).attr("id");
				   if(id!=null&&id!=""){
					   id=id.replace(/\[\d*\]/g,"["+seq+"]");
					   $(this).attr("id",id);
				   }
				   var className=$(this).attr("class");
				   if(className!=null&&className!=""){
					   className=className.replace(/\[\d*\]/g,"["+seq+"]");
					   $(this).attr("class",className);
				   }
			   });
		   }
		 }
	  );
	}else{
		$("#"+tblId+" tr").each(function(){
			  
			   var seq=$(this).get(0).rowIndex;//获得行数
			   if(seq>1){//如果有行  显示时display行不计入类，故只减1
				   
				   seq=seq-1;
				   var seq_no=$(this).find("[name$='seq_no']");
				   if(seq_no.is("span"))
					   seq_no.html(seq);
				   else
					   seq_no.val(seq);
				   
				   seq=""+(seq-1);
				   if(seq.length==1)
					   seq="0"+seq;
				  //替换相应的name参数的seq
				  $(this).find("input,span,textarea,select").each(function(){
					   var name=$(this).attr("name");
					   if(name!=null&&name!=""){
						   name=name.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("name",name);
					   }
					   var id=$(this).attr("id");
					   if(id!=null&&id!=""){
						   id=id.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("id",id);
					   }
					   var className=$(this).attr("class");
					   if(className!=null&&className!=""){
						   className=className.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("class",className);
					   }
				   });
			   }
			 }
		  );
	}
} */
/**
 * 限制Table行数 
 * @param tableId表格id
 * @param max最大行数
 * @returns {Boolean}
 */
/* function checkTabLimit(tableId,max,message)
{
	 if(tableId=='tblAttendOrg'){
	var maxLinNum=$("#"+tableId+" tr[name='externTr']").length-2;
		if(maxLinNum>=max)
		{
			scmWarn(message);
			return false;
		}
	return true;
	 }else{
		 var maxLinNum=$("#"+tableId+" tr").length-2;
			
			if(maxLinNum>=max)
			{
				scmWarn(message);
				return false;
			}
		return true;
	 }
}
	function initTreeValue(treeId, treeNode) {

		if (!(treeNode && treeNode.level > 0) && treeId!='applicant_subject' && treeId.indexOf('province') == -1 ) {
			scmWarn($("#" + treeId).attr("label")
					+ messageTip.researchAreaInvalidDisciplineCode);
			if (treeNode.level == 0) {
				$("#" + treeId).val("");
				$("#" + treeId).parents("td").find(
						"[name$='" + treeId + "_code'],[id$='" + treeId
								+ "_code']").val("");
				$("#" + treeId).parents("td").find(
						"[name$='" + treeId + "_name'],[id$='" + treeId
								+ "_name']").val("");
			}
			return false;
		}
		if(treeId .indexOf('province')>-1){
			var oldval = $("#" + treeId).parents("td[name='innerTd']").find(
					"[name$='" + treeId + "_code'],[id$='" + treeId + "_code']")
					.val();
			var oldname = $("#" + treeId).parents("td[name='innerTd']").find(
					"[name$='" + treeId + "_name'],[id$='" + treeId + "_name']")
					.val();
			}else{
				var oldval = $("#" + treeId).parents("td").find(
						"[name$='" + treeId + "_code'],[id$='" + treeId + "_code']")
						.val();
				var oldname = $("#" + treeId).parents("td").find(
						"[name$='" + treeId + "_name'],[id$='" + treeId + "_name']")
						.val();
			}
		oldval = $.trim(oldval);
		oldname = $.trim(oldname);
		var str = treeNode.name;
		var obj = treeNode.parentNode;
		while (obj != null) {
			str = obj.name + "-" + str;
			obj = obj.parentNode;
		}
		if (treeId == 'impl_area') {

			if (treeNode.checked) {
				if (oldname != '')
					oldname += ',';
				if (oldval != '')
					oldval += ',';
				if(oldval.indexOf(treeNode.id)==-1)
					$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val(oldval + treeNode.id);
				if(oldname.indexOf(str)==-1){
					$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val(oldname + str);
					$("#" + treeId).parents("td").find("[name='" + treeId + "'],[id='" + treeId + "']").val(oldname + str);
				}
			} else {
				$("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val(("," + oldval).replace(',' + treeNode.id, '').substring(1));
				$("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val(("," + oldname).replace("," + str, '').substring(1));
				$("#" + treeId).parents("td").find("[name='" + treeId + "'],[id='" + treeId + "']").val(("," + oldname).replace("," + str, '').substring(1));
			}
		} else if(treeId .indexOf('province')>-1){
			$("#" + treeId).parents("td[name='innerTd']")
					.find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val(treeNode.id);
			$("#" + treeId).parents("td[name='innerTd']")
					.find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val(str);
		}else
		{
			$("#" + treeId).parents("td")
					.find("[name$='" + treeId + "_code'],[id$='" + treeId+ "_code']").val(treeNode.id);
			$("#" + treeId).parents("td")
					.find("[name$='" + treeId + "_name'],[id$='" + treeId+ "_name']").val(str);
	
	}
	}
	
	function InitChange(id,val){
		//index 添加记录数 row 行数
		var index  = $.trim(id.replace(val,""));
		var row = val.substr(val.length-1,val.length);
		var dept_name = $.trim($("#dept_name"+row+""+index).val());
		var dept_participation = $.trim($("#dept_participation"+row+"_value"+index).val());
		var dept_number = $.trim($("#dept_number"+row+""+index).val());
		
		if(dept_name!="" || dept_participation != "" || dept_number !=""){
			$("#dept_name"+row+""+index).addClass("required");
			$("#dept_participation"+row+"_value"+index).addClass("required");
			$("#dept_number"+row+""+index).addClass("required");
		}else{
			$("#dept_name"+row+""+index).removeClass("required");
			$("#dept_participation"+row+"_value"+index).removeClass("required");
			$("#dept_number"+row+""+index).removeClass("required");
		}
		
		
	}
	
	$(function(){
		var maxLinNum=$("#tblAttendOrg tr[name='externTr']").length-2;
		for(var i=0;i<= maxLinNum;i++){
			InitChange("dept_name1"+i,"dept_name1");
			InitChange("dept_name2"+i,"dept_name2");
			InitChange("dept_name3"+i,"dept_name3");
		}
	}); */
	
	
</script>
					